package com.example.emos.api.service.impl;

import com.example.emos.api.common.util.PageUtils;
import com.example.emos.api.db.dao.TbModelDao;
import com.example.emos.api.db.pojo.TbModel;
import com.example.emos.api.service.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
@Service
 public class ModelServiceImpl implements ModelService {
    @Autowired
    TbModelDao tbModelDao;
    @Override
    public PageUtils searchModelByPage(HashMap param) {
        ArrayList<HashMap> list= tbModelDao.searchModelByPage(param);
        long count=tbModelDao.searchModelCount(param);
        int start=(Integer) param.get("start");
        int length=(Integer) param.get("length");
        PageUtils pageUtils=new PageUtils(list,count,start,length);
        return pageUtils;
    }

    @Override
    public int insertModel(TbModel model) {
        HashMap hashMap=new HashMap();
        hashMap.put("name",model.getName());
        hashMap.put("mId",model.getMId());
       int hasCount= tbModelDao.countByNameOrMId(hashMap);
       if(hasCount>0){
           return -1;
       }else{
           return tbModelDao.insert(model);
       }
    }

    @Override
    public int updateByPrimaryKeySelective(TbModel record) {
        return tbModelDao.updateByPrimaryKeySelective(record);
    }
}
